<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="header::header"></head>
<script type="text/javascript">
	function ResetPwd(value, row, index){
		return "<a class='easyui-linkbutton dgitemresetPwd' style='width:25px;height:16px;' iconCls='icon-pencil' onclick='onItemReset("
		+ index + ")' title='重置密码' plain='true'></a> ";
	};
	function onItemReset(index){
		onClearSelected();
		var rowData = getRowById(index);
		onResetPwdHandler(rowData);
	};
	function onResetPwdHandler(row) {
		if (row == null) {
			$.messager.alert("提示", "请选择后，再操作！");
			return;
		}
		$.ajax({
			url:"resetPwd",
			data:{
				iid:row.iid,
				
				},
			type : "post",
			dataType : "JSON",
			success : function(data){
				if(data.success){
                  
                     	$.messager.alert("提示", data.msg);
                     }
			},
			error:function(){
				$.messager.alert("提示", "重置失败，请联系管理员!");
				return;
			}
		});
	};

    $(document).ready(function() {
        $("#deletebtn").hide();
        $("#newbtn").click(function () {
            $("#cname").textbox({disabled: false});
            onNewHandler();
        });
        // 新增，修改 提交
        $("#dlg-savebtn1").click(function () {
            var b = true;
            var mobile = $('#cmobile').textbox("getValue");
            var reg = /^1[3456789]{1}\d{9}$/;
            if (!reg.test(mobile)) {
                b = false;
                alert("请输入正确的手机号！")
            }
            var cemail = $('#cemail').textbox("getValue");
            //  /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/
            var reg1 = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
            if (!reg1.test(cemail)) {
                b = false;
                alert("请输入正确的邮箱！")

            }
            if (b) {
                onSubmit();
            }

        });
        $("#iusertype").combobox({
            "onChange": function () {
                var i = $("#iusertype").combobox("getValue");
					if(i==1){

                        $("#iorgname").combobox("setValue",0);
                        $("#iorgname").combobox("setText","人民银行");
                        $("#iorgname").attr("readonly","readonly");
                        $("#iconsultantid").combobox("setValue",0);
                        $("#glgw").hide();
					}else if(i==2){
						//url:'../dicdetails/findItems?ckey=iusertype',
                        $("#iorgname").combobox({url:"../bank/findItems"})
                        $("#iconsultantid").combobox("setValue",0);
                        $("#glgw").show();

					}else{
                        $("#iorgname").combobox({url:"../company/findItems"})
                        $("#iconsultantid").combobox("setValue",0);
                        $("#glgw").hide();
					}
            }
        });
        $("#iorgname").combobox({
            "onChange": function () {
                $("#corgname").val($("#iorgname").combobox("getText"));
            }
        });
	})

    function onItemOptEdit1(value, row, index) {
        return "<a class='easyui-linkbutton dgitemedit' style='width:25px;height:16px;' iconCls='icon-edit' onclick='onItemEdit1("
            + index + ")' title='编辑' plain='true'></a> ";
    }

    function onItemEdit1(index) {
        onClearSelected();
        var rowData = getRowById(index);
        onOldEditHandler1(rowData);
    }

    function onOldEditHandler1(row) {
        $("#cname").textbox({disabled: true});
        if (row == null) {
            $.messager.alert("提示", "请选择后，再操作！");
            return;
        }
        // 清空表单
        $("#dataform").form("clear");
        $("#dlg").dialog({
            iconCls: "icon-edit",
            title: "修改" + indexname
        });
        // $("#dlg").dialog("setTitle", "编辑");
        $("#dlg").dialog("open");
        $("#dlg").window("center");
        opttype = "edit";
        $("#dlg-savebtn").linkbutton({
            "text": "修改"
        });
        try {
            if (subEditHandler && typeof (subEditHandler) == "function") {
                subEditHandler(row);
            }
        } catch (e) {

        }
        $("#dataform").form("load", row);
        $("#dlg-savebtn").show();
    }
</script>
<body>
	<div id="dgtoolbar" class="datagrid-toolbar" th:include="GridToolBar::toolBar"></div>
	<table id="dg" class="easyui-datagrid" data-options="url:'pageQuery',idField:'iid',rownumbers:true,singleSelect:false,method:'post',toolbar:'#dgtoolbar',pagination:true,pageSize:20,pageList:[20,30,50],fit:true,onLoadSuccess:onDGLoadSuccess">
		<thead>
			<tr>
				<th data-options="field:'iid'" checkbox="true" />
				<th data-options="field:'cname'" width="120" align="center">登录账号</th>
				<th data-options="field:'cnickname'" width="120" align="center">姓名</th>
				<th data-options="field:'cstatusname'" width="80" align="center">状态</th>
				<th data-options="field:'cmobile'" width="120" align="center">手机号</th>
				<th data-options="field:'cemail'" width="180" align="center">邮箱</th>
				<th data-options="field:'iusertype'" width="150" align="center" formatter="Data.iusertypeFormatter">用户类型</th>
				<th data-options="field:'corgname'" width="220" align="center">所属单位</th>
				<th data-options="field:'cunit'" width="130" align="center">二级单位</th>
				<th data-options="field:'ispassed'" width="130" align="center" formatter="Data.issueFormat">是否通过审核</th>
				<th data-options="field:'ctype'" width="80" align="center" formatter="Data.istypeFormatter">注册类型</th>
				<th data-options="field:'rolename'" width="80" align="center">角色</th>
				<th data-options="field:'cpwd',formatter:ResetPwd" width="60" align="center">重置密码</th>
				<th data-options="field:'opt',formatter:onItemOptEdit1" width="40" align="center">修改</th>
				<th data-options="field:'opt1',formatter:onItemOptDelete" width="40" align="center">删除</th>
				<th data-options="field:'opt2',formatter:onItemOptShow" width="40" align="center">查看</th>
			</tr>
		</thead>
	</table>
	<div id="dlg" class="easyui-dialog" title="操作" style="padding: 5px" data-options="buttons: '#dlg-buttons',closed:'true',modal:true">
		<form id="dataform" method="post" enctype="multipart/form-data">
			<table>
				<tr>
					<td colspan="2"><input name="iid" id="iid" type="hidden">
						<input name="corgname" id="corgname" type="hidden">
						</input>
				</tr>
				<tr>
					<td>登录账号:</td>
					<td><input name="cname" id="cname" class="easyui-textbox" style="width: 200px" required="required"/>
					</td>
				</tr>
				<tr>
					<td>姓名:</td>
					<td><input name="cnickname" class="easyui-textbox" style="width: 200px"></input></td>
				</tr>
				<tr>
					<td>邮箱:</td>
					<td><input name="cemail" id="cemail" class="easyui-textbox" style="width: 200px"></input></td>
				</tr>
				<tr>
					<td>手机号:</td>
					<td><input name="cmobile" id="cmobile" class="easyui-textbox" style="width: 200px"></input></td>
				</tr>
				<tr>
					<td>角色:</td>
					<td><input name="rid" class="easyui-combobox" style="width:200px" data-options="url:'../role/findItems',valueField:'iid',textField:'cname',required:'true',panelHeight:'auto'"/></td>
				</tr>
				<tr>
					<td>是否审核:</td>
					<td><input name="ispassed" class="easyui-combobox" style="width:200px" data-options="url:'../dicdetails/findItems?ckey=sf',valueField:'cvalue',textField:'cname',required:'true',panelHeight:'auto'"/></td>
				</tr>
				<tr>
					<td>用户类型:</td>
					<td><input name="iusertype" id="iusertype" class="easyui-combobox" style="width:200px" data-options="url:'../dicdetails/findItems?ckey=iusertype',valueField:'cvalue',textField:'cname',required:'true',panelHeight:'auto'"/></td>
				</tr>
				<tr>
					<td>所属单位:</td>
					<td><input name="iorgname" id="iorgname" class="easyui-combobox" style="width:200px" data-options="valueField:'iid',textField:'cname',required:'true',panelHeight:'200px'"/></td>
				</tr>

				<tr>
					<td>二级单位:</td>
					<td><input name="cunit" class="easyui-textbox" style="width: 200px"></input></td>
				</tr>
				<tr id="glgw">
					<td>关联顾问:</td>
					<td><input name="iconsultantid" id="iconsultantid" class="easyui-combobox" style="width:200px" data-options="url:'../consultant/findItems',valueField:'iid',textField:'cname',panelHeight:'200px'"/></td>
				</tr>
				<tr>
					<td>状态:</td>
					<td><!-- <input name="cstatus" class="easyui-combobox" style="width: 150px"></input> -->
						<select name="cstatus" class="easyui-combobox" style="width:200px" data-options="panelHeight:'auto',required:'true'">
							<option value="0">正常</option>
							<option value="1">禁用</option>
						</select>
					</td>
				</tr>
			</table>
		</form>
	</div>
	<div id="dlg-buttons">
		<a id="dlg-savebtn1" href="javascript:void(0)" style="width: 50" class="easyui-linkbutton"
		   iconCls="icon-ok">保存</a>
		<a id="dlg-closebtn" href="javascript:void(0)" style="width: 50" class="easyui-linkbutton" iconCls="icon-no">关闭</a>
	</div>
	<div id="dlg-query" class="easyui-dialog" title="查询" style="padding: 5px" data-options="buttons: '#dlg-query-buttons',closed:'true',modal:true">
		<form id="dataform-query" method="post">
			<table>
				<tr>
					<td>登录账号:</td>
					<td><input name="cname" class="easyui-textbox" style="width: 150px" /></td>
				</tr>
				<tr>
					<td>姓名:</td>
					<td><input name="cnickname" class="easyui-textbox" style="width: 150px" /></td>
				</tr>
				<tr>
					<td>用户状态:</td>
					<td><!-- <input name="istatus" class="easyui-combobox" data-options="data:[],valueField:'value',textField:'label',panelHeight:'auto'" style="width: 150px" /> -->
						<select name="cstatus" class="easyui-combobox" style="width:150px" data-options="panelHeight:'auto'">
							<option value="0">正常</option>
							<option value="1">禁用</option>
						</select>
					</td>
				</tr>
				<!-- <tr>
					<td>注册时间:</td>
					<td><input name="dlastlogin" class="easyui-datebox" style="width: 150px" /></td>
					<td>结束时间:</td>
					<td><input name="ccomment" class="easyui-datebox" style="width: 150px" /></td>
				</tr> -->
			</table>
		</form>
	</div>
	<div id="dlg-query-buttons">
		<a id="dlg-query-savebtn" href="javascript:void(0)" style="width: 50" class="easyui-linkbutton" iconCls="icon-search">查询</a>
		<a id="dlg-query-closebtn" href="javascript:void(0)" style="width: 50" class="easyui-linkbutton" iconCls="icon-no">关闭</a>
	</div>
</body>
<script type="text/javascript" th:src="@{/common/GridView.js}"></script>
</html>